package com.csmy.minyuanplus.ui.fragment.college;

import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;

import com.csmy.minyuanplus.R;
import com.csmy.minyuanplus.event.EventModel;
import com.csmy.minyuanplus.model.college.College;
import com.csmy.minyuanplus.ui.fragment.BaseFragment;
import com.zhy.adapter.recyclerview.CommonAdapter;
import com.zhy.adapter.recyclerview.base.ViewHolder;
import com.zhy.autolayout.utils.AutoUtils;

import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;

/**
 * 民院页面
 * Created by Zero on 16/8/20.
 */
public class CollegeFragment2 extends BaseFragment {
    @Bind(R.id.id_college_rv)
    RecyclerView mRecyclerView;
    CommonAdapter<College> mAdapter;
    private List<College> mDatas;
    private GridLayoutManager mGridLayoutManager;



    public static CollegeFragment2 newInstance(){return new CollegeFragment2();}

    @Override
    protected void initView(View view, Bundle saveInstanceState) {
        getItemData();

        mAdapter = new CommonAdapter<College>(getContext(),R.layout.item_college,mDatas) {
            @Override
            public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
                ViewHolder holder = super.onCreateViewHolder(parent, viewType);
                AutoUtils.auto(holder.getConvertView());
                return holder;
            }
            @Override
            protected void convert(ViewHolder holder, College college, int position) {
                holder.setBackgroundRes(R.id.id_college_item_iv,college.getImgResId());
                holder.setText(R.id.id_college_item_tv,college.getItemName());
            }
        };

        mGridLayoutManager = new GridLayoutManager(getContext(),3);
        mRecyclerView.setLayoutManager(mGridLayoutManager);
        mRecyclerView.setHasFixedSize(true);
        mRecyclerView.setAdapter(mAdapter);
    }

    private void getItemData(){
        mDatas = new ArrayList<>();
        String[] titles = {getString(R.string.grade_query),getString(R.string.activity_order)
            ,getString(R.string.express),getString(R.string.atm)};
        int[] imgs = {R.mipmap.express,R.mipmap.express,R.mipmap.express,R.mipmap.express};
        for (int i = 0; i < titles.length; i++) {
            mDatas.add(new College(titles[i],imgs[i]));
        }
    }


    @Override
    protected int getLayoutId() {
        return R.layout.fragment_college2;
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onUserEvent(EventModel eventModel){

    }
}
